#include<iostream>
#include<map>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m;
int a[N], b[N];
int d[N];
int main()
{
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		sum += c;
		d[a] += c;
		d[b + 1] -= c;
	}
	int ans = 1e9 + 10;
	for (int i = 1; i <= m; i++) {
		d[i] += d[i - 1];
		//cout << "d[i]==" << d[i] << endl;
		ans = min(ans, d[i]);
	}
	//cout << "ans==" << ans << endl;
	cout << sum - ans << endl;
	return 0;
}